package cn.utils.excelutil;
import java.io.*;
public class ReadInTxt{
    public static void main(String[] args){
        getLineNumber("c:\\test.txt");
    }
    // 统计行数
    public static int getLineNumber(String fileName){
        // long start = System.currentTimeMillis();
        int lineNum = 0;
        File fp = new File(fileName);
        if(!fp.exists()){
            lineNum = 0;
        } else{
            char[] buf = new char[8192];
            LineNumberReader lnr = null;
            try{
                lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(fileName)));
                while(lnr.read(buf) != -1){
                    ;
                }
                lineNum = lnr.getLineNumber() + 1;
            } catch(FileNotFoundException e){
                e.printStackTrace();
            } catch(IOException e){
                e.printStackTrace();
            } finally{
                try{
                    if(null != lnr){
                        lnr.close();
                    }
                } catch(IOException ex){
                    ex.printStackTrace();
                }
            }
        }
        // long end = System.currentTimeMillis();
        return lineNum;
    }
}
